package com.chinairi.mall.controller;


import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.ProjectPlanReturnVO;
import com.chinairi.mall.model.ProjectPlanReqDetail;
import com.chinairi.mall.model.ProjectPlanReturn;
import com.chinairi.mall.model.ProjectPlanReturnDetail;
import com.chinairi.mall.service.IProjectPlanReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gsl
 * @since 2020-10-24
 */
@RestController
@RequestMapping("/project-plan-return")
public class ProjectPlanReturnController extends BaseController {

    @Autowired
    private IProjectPlanReturnService iProjectPlanReturnService;

    /**
     * 新增退料单
     *
     * @param projectPlanReturnVO
     * @throws IOException
     */
    @PostMapping("/add")
    public void addReturn(@RequestBody ProjectPlanReturnVO projectPlanReturnVO) throws IOException {
        iProjectPlanReturnService.addReturn(projectPlanReturnVO);
        ResponseUtil.showMessage("success", "新增退料成功", "");
    }

    /**
     * 获取退料列表
     *
     * @throws IOException
     */
    @GetMapping("/getList")
    public void getList(String flag) throws IOException {
        List<ProjectPlanReturn> projectPlanReturnList = iProjectPlanReturnService.getList(flag);
        ResponseUtil.showMessage("success", "获取退料单列表成功", projectPlanReturnList);
    }

    /**
     * 获取退料单详情
     *
     * @param pprId
     * @throws IOException
     */
    @GetMapping("/getReturnDetail")
    public void getReturnDetail(String pprId) throws IOException {
        ProjectPlanReturnVO projectPlanReturnVO = iProjectPlanReturnService.getReturnDetail(pprId);
        ResponseUtil.showMessage("success", "获取退料详情成功", projectPlanReturnVO);
    }


    /**
     * 更新退料单状态
     *
     * @param pprId
     * @param state
     * @throws IOException
     */
    @PostMapping("/updateState")
    public void updateState(String pprId, String state) throws IOException {
        iProjectPlanReturnService.updateState(pprId, state);
        ResponseUtil.showMessage("success", "更新状态成功", "");
    }

    /**
     * 筛选可退的物料
     *
     * @param projectPlanReturnVO
     * @throws IOException
     */
    @PostMapping("/filterReturnMat")
    public void filterReturnMat(@RequestBody ProjectPlanReturnVO projectPlanReturnVO) throws IOException {
        ProjectPlanReturnVO projectPlanReturnVOResult = iProjectPlanReturnService.filterReturnMat(projectPlanReturnVO);
        if (projectPlanReturnVOResult.getProjectPlanReturnDetailList().size() == 0) {
            ResponseUtil.showMessage("success", "您暂时没有可退的物料", "");
        } else {
            ResponseUtil.showMessage("success", "获取可退物料成功", projectPlanReturnVOResult);
        }
    }

}
